<?php   if ( ! defined('BASEPATH')) exit('No direct script access allowed');



// BASE_URL
if(!function_exists('ROOT_PATH')){
	function ROOT_PATH($url=''){
		$CI =& get_instance();   //get CI object
		return $CI -> config -> item('base_url') . $url;
	}
}


//图片和CSS文件所在的路径
if (!function_exists('IMAGE_PATH')){
	function IMAGE_PATH($imagename=''){
		$CI =& get_instance();   //get CI object
		return $CI -> config -> item('image_url') . $imagename;
	}
}


// url of login page
if (!function_exists('LOGIN_PAGE')){
	function LOGIN_PAGE($url=''){
	   return ROOT_PATH() . 'login' . $url;	
	}
}

//url of register page
if (!function_exists('REGISTER_PAGE')){
	function REGISTER_PAGE($url=''){
		return ROOT_PATH() . 'register' . $url;
	}
}


//url of myqiqu page
if (!function_exists('MYQIQU_PAGE')){
	function MYQIQU_PAGE($url = ''){
		return ROOT_PATH() . 'myqiqu'. $url;
	}
}

//url of myaccount page
if (!function_exists('MYACCOUNT_PAGE')){
	function MYACCOUNT_PAGE($url = ''){
		return ROOT_PATH() . 'myaccount'. $url;
	}
}


//url of CAPTCHA image
if (!function_exists('CAPTCHA_IMG')){
	function CAPTCHA_IMG(){
         return ROOT_PATH() . 'validatecode';
	}
}

//url of CAPTCHA image +  javascript random code
if (!function_exists('CAPTCHA_IMG_RAN')){
	function CAPTCHA_IMG_RAN(){
		return "'" . ROOT_PATH() . "validatecode?code=' + Math.random();" ;
	}
}

//check if given email is a valid email address, by regular expression 
if (!function_exists('IsValidEmail')){
	function IsValidEmail($email){
		error_reporting(0);
		//return eregi("^[a-zA-Z]+@[a-zA-Z]+\.[a-zA-Z]+$",$email);
		return eregi("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", $email);
	}		
}


//get email's website
if (!function_exists('emailWebsite')){
	function emailWebsite($Email){
		$default = 'http://www.google.com';   //if email is not available
		
		$result =  explode('@', $Email);     //EXPLODE is same as split function, but faster and stabler.
		if (count($result)==2){
			return 'http://www.' . $result[1];
		} 
		else
			return $default;
		
	}
}
//Display user defined error message
//$data passing parameters for error display message page
//$msg passing the error message	
if (!function_exists('ErrorMsg')){
	function ErrorMsg($msg){
		try{
		  $data['error_url'] = current_url();   //get current page's url
		}
		catch (Exception $e) {
			$data['error_url'] ='Unknown page.';			
		}
		$data['error_msg'] = $msg;                               //error message
		$CI = & get_instance();  
		$CI ->load -> view('error_view', $data);
	}
}	


// retrivel global setting with given key
if (!function_exists('GlobalSettings')){
	function GlobalSettings($para){
		$CI = & get_instance();  
		$CI->load->model('system_model');
		$settings = $CI -> system_model ->LoadGlobalSettings();    //load global settings 

		return $settings[$para];
	}
}






	


